package com.ljx.mq.springboot.controller;

import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class ProduceController {

    @Autowired
    private RabbitTemplate rabbitTemplate;


    @GetMapping("/send/{msg}")
    public String send(@PathVariable("msg") String msg){
        // 简单模式
        // rabbitTemplate.convertAndSend("", "helloBoot", msg);

        // 工作队列模式
        for (int i = 0; i < 20; i++){
            rabbitTemplate.convertAndSend("", "helloBoot1", msg);
        }
        return msg;
    }

    @GetMapping("/send1/{msg}")
    public String send1(@PathVariable("msg") String msg){
        // pubsub订阅模式
        // rabbitTemplate.convertAndSend("pubsubBoot", "", msg);

        // routing模式
        // rabbitTemplate.convertAndSend("routingBoot", "error", msg);

        // topic模式
        rabbitTemplate.convertAndSend("topicBoot", "user.insert", msg);
        return msg;
    }

}
